/**
 * LS_RequestPacket.java
 *
 * @author Hagen Boehm
 */


package SSF.OS.OSPFv2;


import java.util.Vector;
import java.util.Enumeration;
import SSF.OS.*;


// ========================= class SSF.OS.OSPFv2.LS_RequestPacket ============================ //
/**
 * This class implements an OSPF link state request packet. The following from RFC 2328 was
 * not included:
 * 1.) Version
 * 2.) Packet length
 * 3.) Checksum
 * 4.) Authentication 
 */
public class LS_RequestPacket extends ProtocolMessage {

  private Vector requestedLSAs;

  // ----------------------------- constructor LS_RequestPacket ---------------------------- //

  public LS_RequestPacket() {
    requestedLSAs = new Vector();
  }

  // --------------------------------- LS_RequestPacket.put --------------------------------- //
  /** 
   *  append the copy of a key of a requested LSA to the Vector requestedLSAs.
   */
  public void put(String key) {
    requestedLSAs.add(key.substring(0));
  }

  // ------------------------------ LS_RequestPacket.getRequests ---------------------------- //
  /**
   *  return all requested LSA in terms of keys in a Vector.
   */
  public Vector getRequests() {
    return requestedLSAs;
  }

  // ------------------------------ LS_RequestPacket.isEmpty -------------------------------- //
  /** Return true if there are no requests stored in this Packet else false. */
  public boolean isEmpty() {
    return requestedLSAs.isEmpty();
  }

  // ----------------------------- LS_RequestPacket.carryPayload ---------------------------- //

  public void carryPayload(ProtocolMessage payload) {
    System.err.println("** Warning: LS_RequestPacket can't take payload; dropping!");
  }

  // ------------------------------- LS_RequestPacket.bytecount ---------------------------- //
  /** Return the total size (in bytes) of this LS Request Packet body. 
   *  All and only fields specified in RFC 2328 are included in calculation!!!
   */
  public int bytecount(){
    return header_bytecount();
  }

  // ---------------------------- LS_RequestPacket.header_bytecount ------------------------- //
  /** Return the size (in bytes) of this header only, don't include a payload. 
   *  Link State Request Packets don't have payload.
   */
  public int header_bytecount(){
    return (12 * requestedLSAs.size());
  }

  // ------------------------------ LS_RequestPacket.copy ---------------------------------- //
  /** Return a copy of this LS Request Packet content. */
  public ProtocolMessage copy() {
    LS_RequestPacket requestCopy = new LS_RequestPacket();
    for (Enumeration req = requestedLSAs.elements(); req.hasMoreElements(); ) {
      requestCopy.put((String)req.nextElement());
    }
    return requestCopy;
  }

  // ---------------------------- LS_RequestPacket.toString -------------------------------- //
  public String toString() {
    String s = "";
    for (Enumeration e = requestedLSAs.elements() ; e.hasMoreElements() ;) {
      s += (String)e.nextElement() + " ";
    }  
    return s;
  }

} //end class LS_RequestPacket




